package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

type App struct {
	output *widget.Label
}

var myApp App

func main() {
	a := app.New()
	w := a.NewWindow("hello, world!")

	output, entry, btn := myApp.makeUI()

	// vbox是垂直摆放的盒子
	w.SetContent(container.NewVBox(output, entry, btn))
	// 设置窗口大小
	w.Resize(fyne.Size{Width: 500, Height: 500})
	w.ShowAndRun()
}

func (app *App) makeUI() (*widget.Label, *widget.Entry, *widget.Button) {
	output := widget.NewLabel("hello, world!")
	entry := widget.NewEntry()
	btn := widget.NewButton("Enter", func() { // 按下按钮后触发
		// 设置文字
		app.output.SetText(entry.Text)
	})
	// 按钮的主题?样式, 比如danger/low/high/...
	btn.Importance = widget.HighImportance

	app.output = output

	return output, entry, btn
}
